import java.util.Arrays;
import java.util.List;

public class DiscountPromotionCalculator implements PromotionCalculator {
    private static final SalesPromotion salesPromotion = new SalesPromotion("50%_DISCOUNT_ON_SPECIFIED_ITEMS", "Half price for certain dishes", Arrays.asList(
            "ITEM0001", "ITEM0022"
    ));

    @Override
    public PromotionResult calculate(List<OrderItem> orderItems) {
        double savedAmount = orderItems.stream()
                .filter(item -> salesPromotion.getRelatedItems().contains(item.getItemId()))
                .map(OrderItem::getAmount)
                .reduce(Double::sum).orElse((double) 0) * 0.5;

        return new PromotionResult(savedAmount, salesPromotion);
    }
}
